package com.cxrj.zhsq.utils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.alibaba.druid.support.json.JSONUtils;

/**
 * 开门接口
 * 
 * @author yuandi
 *
 */
public final class DoorUtil {

	private final static String APPKEY = "5f331161";

	private final static String SECRET = "e7f5863f42f0485d9c973ee5ee35b700";

	private final static String DEFAULT_USER_UUID = "cc78be40ec8611e78168af26905e6f0f";

	/**
	 * 获取默认用户id
	 * 
	 * @return
	 */
	public static String getUserId() {
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("appkey", APPKEY);
		para.put("time", new Date().getTime());
		String token = Encrypt.md5("/openapi/service/base/user/getDefaultUserUuid" + JSONUtils.toJSONString(para) + SECRET);
		try {
			return HttpClientHelper1.invokeRequest("http://61.184.160.116:81/openapi/service/base/user/getDefaultUserUuid?token=" + token, para);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 查询所有的门
	 * 
	 * @param userId
	 * @return
	 */
	public static String getDoor(Integer pageNo, Integer pageSize) {
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("appkey", APPKEY);
		para.put("time", new Date().getTime());
		para.put("pageNo", pageNo);
		para.put("pageSize", pageSize);
		para.put("opUserUuid", DEFAULT_USER_UUID);
		String token = Encrypt.md5("/openapi/service/acs/res/getDoors" + JSONUtils.toJSONString(para) + SECRET);
		try {
			return HttpClientHelper1.invokeRequest("http://61.184.160.116:81/openapi/service/acs/res/getDoors?token=" + token, para);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 开门
	 * 
	 * @param uuid
	 * @param userId
	 * @return
	 */
	public static String openDoor(String uuid) {
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("appkey", APPKEY);
		para.put("time", new Date().getTime());
		para.put("opUserUuid", DEFAULT_USER_UUID);
		para.put("doorUuid", uuid);
		para.put("command", 2);
		String token = Encrypt.md5("/openapi/service/acs/control/synControl" + JSONUtils.toJSONString(para) + SECRET);
		try {
			return HttpClientHelper1.invokeRequest("http://61.184.160.116:81/openapi/service/acs/control/synControl?token=" + token, para);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 获取所有监控点
	 * 
	 * @param userId
	 * @return
	 */
	public static String getHls(Integer pageNo, Integer pageSize) {
		Map<String, Object> para = new HashMap<String, Object>();
		para.put("appkey", APPKEY);
		para.put("time", new Date().getTime());
		para.put("pageNo", pageNo);
		para.put("pageSize", pageSize);
		para.put("opUserUuid", DEFAULT_USER_UUID);
		String token = Encrypt.md5("/openapi/service/vss/res/getCamerasEx" + JSONUtils.toJSONString(para) + SECRET);
		try {
			return HttpClientHelper1.invokeRequest("http://61.184.160.116:81/openapi/service/vss/res/getCamerasEx?token=" + token, para);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public static void main(String[] args) {
		 System.out.println(openDoor("d514d2b0a12643baa5f59d236d59838c"));
//		System.out.println(getUserId());
	}
}
